module.exports = {
  base64Encode: function (r) {
    for (
      var t,
        a,
        e,
        c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
        h = 0,
        o = r.length,
        A = "";
      h < o;

    ) {
      if (((t = 255 & r.charCodeAt(h++)), h == o)) {
        (A += c.charAt(t >> 2)), (A += c.charAt((3 & t) << 4)), (A += "==");
        break;
      }
      if (((a = r.charCodeAt(h++)), h == o)) {
        (A += c.charAt(t >> 2)),
          (A += c.charAt(((3 & t) << 4) | ((240 & a) >> 4))),
          (A += c.charAt((15 & a) << 2)),
          (A += "=");
        break;
      }
      (e = r.charCodeAt(h++)),
        (A += c.charAt(t >> 2)),
        (A += c.charAt(((3 & t) << 4) | ((240 & a) >> 4))),
        (A += c.charAt(((15 & a) << 2) | ((192 & e) >> 6))),
        (A += c.charAt(63 & e));
    }
    return A;
  },
  base64Decode: function (r) {
    var t,
      a,
      e,
      c,
      h,
      o,
      A,
      n,
      d,
      C,
      f = [
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57,
        58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,
        9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1,
        -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
        39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
      ];
    if ((A = r.length) % 4 != 0) return "";
    if (
      /[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\+\/\=]/.test(
        r,
      )
    )
      return "";
    for (
      d = A,
        (n = "=" == r.charAt(A - 2) ? 1 : "=" == r.charAt(A - 1) ? 2 : 0) > 0 &&
          (d -= 4),
        d = 3 * (d >> 2) + n,
        C = new Array(d),
        h = o = 0;
      h < A &&
      -1 != (t = f[r.charCodeAt(h++)]) &&
      -1 != (a = f[r.charCodeAt(h++)]) &&
      ((C[o++] = String.fromCharCode((t << 2) | ((48 & a) >> 4))),
      -1 != (e = f[r.charCodeAt(h++)])) &&
      ((C[o++] = String.fromCharCode(((15 & a) << 4) | ((60 & e) >> 2))),
      -1 != (c = f[r.charCodeAt(h++)]));

    )
      C[o++] = String.fromCharCode(((3 & e) << 6) | c);
    return C.join("");
  },
};
